import ServiceOutlets from './components/serviceOutlets.vue'
import VueForm from 'vue-form'
import Query from './query'
import SuccessDialog from 'success_alert'
import ErrorDialog from 'error_alert'

var options = {
  validators: {
    'cellphone-validator': function(value, attrValue, vnode) {
      return /^\d{11}$/.test(value)
    }
  }
}

require('./app')({
  'serviceOutlets': ServiceOutlets
}, function() {

}, {
  formstate: {},
  customer: {
    name: '',
    mobile: '',
    address: '',
    job: '',
    demand: '',
    product_no: '',
    purchase_date: ''
  }
}, {}, {
  onSubmit: function() {
    if (this.formstate.$invalid) {
      return;
    }
    Query.post('/join_records', {
      join_record: this.customer
    }).then((response) => {
      if (response.flag) {
        SuccessDialog.show(response.message)
      } else {
        ErrorDialog.show(response.message)
      }
    })
  },
  saleRecordOnSubmit: function() {
    // console.log('xxx', this.customer)
    // console.log(this.formstate.$invalid)
    // console.log(this.formstate)
    if (this.formstate.$invalid) {
      return;
    }
    const sale_record = {
      name: this.customer.name,
      address: this.customer.address,
      mobile: this.customer.mobile,
      demand: this.customer.demand,
      product_no: this.customer.product_no,
      purchase_date: this.customer.purchase_date
    }
    console.log(sale_record)
    Query.post('/sale_records', {
      sale_record: sale_record
    }).then((response) => {
      if (response.flag) {
        SuccessDialog.show(response.message)
      } else {
        ErrorDialog.show(response.message)
      }
    })
  }
}, [new VueForm(options)], {

})
